<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>
        function go(url) { // 用户方法的不会触发
            history.pushState({}, null, url)
        }
    </script>

    <a onclick="go('#/a')">a应用</a>
    <a onclick="go('#/b')">b应用</a>

    <!-- <a href="#/a">a应用</a>
    <a href="#/b">b应用</a> -->
    <!-- <script src="https://cdn.bootcdn.net/ajax/libs/single-spa/5.9.3/umd/single-spa.min.js"></script> -->
    <script type="module">
        // const { registerApplication, start } = singleSpa
        import { registerApplication, start } from  './single-spa/single-spa.js'

        let app1 = {
            bootstrap: [
                async() => {
                    console.log('app1 bootstrap')
                },
            ],
            mount: async() => {
                console.log('app1 mount')
            },
            unmount: async() => {
                console.log('app1 unmount')
            }
        }

        let app2 = {
            bootstrap: async() => {
                console.log('app2 bootstrap')
            },
            mount: async() => {
                console.log('app2 mount')
            },
            unmount: async() => {
                console.log('app2 unmount')
            }
        }
        registerApplication('a', async () => app1, location => location.hash.startsWith('#/a'))
        registerApplication('b', async () => app2, location => location.hash.startsWith('#/b'))
        start()
        window.addEventListener('hashchange', function () {
            console.log('p ----')
        })
    </script>
</body>
</html>